package com.doodle.common.utils;

import android.os.Handler;

import com.doodle.common.data.AsyncResource;
import com.doodle.common.utils.ThreadPool.Job;

public class SimpleJobExecutor<T> implements AsyncResource.JobExecutor<T> {

	private JobLimiter mThreadPool;
	private Handler mHandler;
	
	public SimpleJobExecutor(int limit) {
		mThreadPool = new JobLimiter(new ThreadPool(), limit);
		mHandler = new Handler();
	}

	@Override
	public Future<T> execute(Job<T> job, FutureListener<T> listener) {
		return mThreadPool.submit(job, listener);
	}

	@Override
	public void runForJobDone(Runnable runnable) {
		mHandler.post(runnable);
	}
	
	public JobLimiter getJobLimiter() {
		return mThreadPool;
	}
}
